package com.ayic.garbagerecycle.mapper;

import com.ayic.garbagerecycle.pojo.WasteRecord;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface WasteMapper {
    /**
     * 根据站点ID查询该站点的所有回收记录
     *
     * @param stationId 站点ID
     * @return 回收记录列表
     */
    @Select("SELECT waste_type_id wasteType, weight, volume, created_at createdAt FROM waste_records WHERE station_id = #{stationID} ORDER BY createdAt DESC LIMIT 10  ")
    List<WasteRecord> selectByStationId(Integer stationId);

    @Select("SELECT waste_type_id wasteType, weight, volume, created_at createdAt FROM waste_records WHERE user_id = #{userId} ORDER BY createdAt DESC LIMIT 5  ")
    List<WasteRecord> queryUserRec(Integer userId);

    @Select("SELECT waste_type_id wasteType, weight, volume FROM waste_records WHERE station_id = #{stationID} ORDER BY waste_records.created_at DESC")
    List<WasteRecord> selectStationHistoryRecords(Integer stationId);
//    @Select("SELECT waste_type_id wasteTypeId, weight, volume, created_at createdAt FROM waste_records WHERE station_id = #{stationID}")
//    List<WasteRecord> selectAllByStationId(Integer stationId);

    @Insert("INSERT INTO waste_records (station_id, waste_type_id, weight, volume, value, created_at,user_id) " +
            "VALUES (#{stationId}, #{wasteType}, #{weight}, #{volume}, #{value}, #{createdAt},#{userId})")
    @Options(useGeneratedKeys = true, keyProperty = "recordId")
    int addRecord(WasteRecord wasteRecord);

    @Select("SELECT waste_type_name FROM waste_types WHERE waste_type_id = #{wasteType}")
    String queryType(Integer wasteType);
}